<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?
require_once  '../classes/ConnectionDB.php';
require_once  '../classes/UtenteManager.php';
require_once  '../classes/TestDataManager.php';
require_once  '../bean/Domanda.php';

$connection =ConnectionDB::getInstance()->connectToDB();
$codiceUtente = $_COOKIE['codiceUtente'];
$codiceTest = $_GET['codiceTest'];
if(isset ($_GET['chiaveTest']))
    $chiaveTest = $_GET['chiaveTest'];

$test = TestDataManager::getInstance()->getTestByCodice($connection, $codiceTest);
$result = UtenteManager::getInstance()->getUtente($connection, $codiceUtente);
if(!isset ($_GET["fromSottomessi"]))
    $domande = TestDataManager::getInstance()->searchDomandeByCodiceTest($connection, $codiceTest);
else
    $domande = TestDataManager::getInstance()->searchDomandeByCodiceTestAndChiave($connection, $codiceTest, $chiaveTest);
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Report domande</title>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/prototype.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/scriptaculous/effects.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/glassbox/glassbox.js" type="text/javascript"></script>
        <style type="text/css">
            @import url("../css/style.css");
            table{
                width: 100%;
            }

            #tableResults td{
                text-align: center;
            }


            #results {
                padding-top: 3%;

            }

            #resultsCont
            {

            }

           

        </style>
        <script type="text/javascript">
            path_to_root_dir = "../glassboxLatest/glassbox.2.0.0/";
            var listaDomande;
            var numItem=8;
            var currentIndex=0;
            var i=0;

            window.onload = function()
            {

                var results = new GlassBox();
                results.init( 'results', '1040px', '470px', 'auto','',true,false);
                results.ipos();
                results.appear();

                ind=0;
                listaDomande = new Array();
<?
for($j=0; $j<count($domande); $j++)
{?>
        listaDomande[i] = "<?= $domande[$j]->getCodiceDomanda() ?>*<?= $domande[$j]->getTestoDomanda()?>*<?= $domande[$j]->getNomeArgomento()?>*<?= $domande[$j]->getTipologia()?>";

        i++;

    <?}?>

            manageNav(0);
        }

        function togli(codice, codiceTest)
        {
            document.getElementById('codiceDomandaDaEliminare').value=codice;
            document.getElementById('codiceTestToUpdate').value=codiceTest;
            document.eliminaForm.submit();
        }

        function addQuestion()
        {
            location.href="../testManaging/newTest_2.php?fromUpdate=1&codiceTest=<?= $test->getCodice()?>&nome=<?= $test->getNome()?>&ore=<?= $test->getOre()?>&minuti=<?= $test->getMinuti()?>";
        }


        function manageNav(ind)
        {
            var tmp= new Array();
            var str="";


<? if(!isset ($_GET["fromSottomessi"]))
{?>
        str +="<img src='../images/icons/PNG/Pen 3.png' height='30' width='30' title='Aggiungi domanda' border='0'/><a href='javascript:addQuestion();'>Aggiungi domanda</a><br />";
    <?}?>
            str += "<table border='1' id='tableResults' cellpadding='5'><tr>"
                +"<th>Codice domanda</th>"
                +"<th>Domanda</th>"
                +"<th>Argomento</th>"
                +"<th>Tipologia</th>"
                +"<th>Dettaglio</th>";
<? if(!isset ($_GET["fromSottomessi"]))
{?>
        str +="<th>Elimina dal test</th>";
    <?}?>
            str += "</tr>";


            for(ind=0;ind<listaDomande.length;ind++)
            {
                tmp=listaDomande[ind].split("*");
                var nomeTipologia;
                if(tmp[3]=='1')
                    nomeTipologia="Vero/Falso";
                else
                    nomeTipologia="Risposta multipla";
                str+="<tr><td>"+tmp[0]+"</td>"+
                    "<td>"+tmp[1]+"</td>"+
                    "<td>"+tmp[2]+"</td>"+
                    "<td>"+nomeTipologia+"</td>"+
                    "<td><a href='detailQuestion.php?codiceDomanda="+tmp[0]+"'><img src='../images/icons/PNG/Magnifying Glass.png' height='30' width='30' title='Dettaglio' border='0'/></a></td>";
<? if(!isset ($_GET["fromSottomessi"]))
{?>
            str += "<td><input type='button' value='Elimina dal test' onclick='javascript:togli("+tmp[0]+", <?= $codiceTest ?>)' /></td></tr>";
    <?}?>

            }


            str +="</table>";
            //                                                    var numTotItem = listaDomande.length;
            //                                                    var numPag = Math.ceil(numTotItem / numItem);
            //                                                    if(numPag > 1)
            //                                                    {
            //                                                        str +="<div id='navigator'><center>";
            //                                                        var current = 0;
            //                                                        var toPrint=1
            //                                                        for(k=1;k<=numPag;k++)
            //                                                        {
            //                                                            str+="<a href='javascript:manageNav("+current+")'>"+toPrint+"</a>&nbsp;&nbsp;";
            //                                                            current= k * numItem;
            //                                                            toPrint = toPrint+1;
            //                                                        }
            //                                                        str+="</center></div>";
            //                                                    }
            document.getElementById('resultsCont').innerHTML=str;
        }

        function showDetail(codice)
        {
            location.href="detailQuestion.php?codiceDomanda=" + codice;
        }
        </script>
    </head>
    <body>
        <form name="eliminaForm" method="POST" action="reportTestListener.php">
            <input type="hidden" name="operation" value="eliminaDomanda" />
            <input type="hidden" id="codiceDomandaDaEliminare" name="codiceDomanda" />
            <input type="hidden" id="codiceTestToUpdate" name="codiceTest" />

        </form>
        <?php include '../portal/header.php';?>
        <center>

            <div id="results"><div id="resultsCont"></div></div>
        </center>
    </body>
</html>
